Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

isinview

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

isinview

Watch elements entering or leaving viewport

  • 2.2.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40
increased by207.69%
Maintainers
1
Weekly downloads
 
Created
Source

Isinview npm David npm type definitions

Watch elements entering or leaving a viewport.

Installation

npm install isinview

Demo

Screencast

How to use

import { isInView, isOutOfView } from 'isinview'

isInView(document.querySelector('#target'), (target) => {
	console.log('Target element has entered the viewport')
	target.classList.add('is-visible')
})

isOutOfView(document.querySelector('#target'), (target) => {
	console.log('Target element has left the viewport')
	target.classList.remove('is-visible')
})

Options

import { isInView } from 'isinview'

const options = {
	once: true, // Run callback only the first time for every target element [true, false]
	threshold: 0.5, // Fraction of target's area that must be visible [0 - 1]
}

isInView(
	document.querySelectorAll('.target'),
	(target) => {
		console.log('Target element has entered the viewport', target)
	},
	options
)

Support

import { isSupported } from 'isinview'

console.log(
	isSupported() ? 'IsInView is supported.' : 'IsInView is not supported!'
)

Based on IntersectionObserver (caniuse).

Polyfill for IE and old Safari:

<script
	crossorigin="anonymous"
	src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"
></script>

Keywords

FAQs

Package last updated on 05 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc